<template>
  <div id="app">
    <Login v-if="!isLoggedIn" @login-success="handleLogin" />
    <Dashboard v-else @logout="handleLogout" />
  </div>
</template>

<script>
import Login from "@/views/Login.vue";
import Dashboard from "@/views/Dashboard.vue";

export default {
  components: {Login, Dashboard},
  data() {
    return {
      isLoggedIn: false, // 控制显示登录/后台
    };
  },
  created() {
    // 页面加载时自动读取 localStorage 判断是否已登录
    this.isLoggedIn = localStorage.getItem("isLoggedIn") === "true";
  },
  methods: {
    handleLogin() {
      this.isLoggedIn = true;
      // 登录成功时保存登录状态
      localStorage.setItem("isLoggedIn", "true");
    },
    handleLogout() {
      this.isLoggedIn = false;
    },
  },
};
</script>
<style>
* {
  padding: 0;
  margin: 0;
}
</style>
